package com.system.healthproject.model.admin.service.impl;

import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.mapper.CardMapper;
import com.system.healthproject.model.admin.service.RechargeService;
import com.system.healthproject.pojo.Card;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RechargeServiceImp implements RechargeService {
    @Autowired
    CardMapper cardMapper;


    @Override
    public boolean insertRechargeCard(Card card) {
        card.setCardCreatetime(new Date());
        int insert = cardMapper.insert(card);
        return insert==1;
    }

    @Override
    public boolean deleteRechargeCard(Integer cardId) {

        return cardMapper.deleteByPrimaryKey(cardId)==1;
    }

    @Override
    public PagesBean<Card> selectList(
            Integer page,
            Integer size,
            String cardType,
            String createStartTime,
            String createEndTime) {
        PagesBean<Card> pagesBean=new PagesBean<>();
        List<Card> cards = cardMapper.selectList((page-1)*size, size, cardType, createStartTime, createEndTime);
        Integer total = cardMapper.getTotal(cardType, createStartTime, createEndTime);
        pagesBean.setData(cards);
        pagesBean.setNowsPage(page);
        pagesBean.setPageSize(size);
        pagesBean.setDataCount(total);
        return pagesBean;
    }
}
